package com.movitech.mobile.cz.base.controller;

import com.movitech.mobile.cz.base.common.util.excel.ExportExcel;
import com.movitech.mobile.cz.base.entity.*;
import com.movitech.mobile.cz.base.impl.SpecialPurchaseReportService;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 
 * 专项采购模块报表接口
 * @author Jack.Gong
 * @since 2018-05-24
 *
 */
@RestController
@RequestMapping("/v1/specialPurchaseReport")
@Api(value = "专项采购模块报表", description = "专项采购模块报表")
public class SpecialPurchaseReportController {

	@Autowired
	private SpecialPurchaseReportService specialPurchaseReportService;

	@PostMapping("/searchSpecialPurchaseDetail")
    @ApiOperation(value = "专项采购详情统计查询", notes = "专项采购详情统计")
	public RestReturnResult searchSpecialPurchaseDetail(@RequestBody SPDetailSearchReqVO reqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult = specialPurchaseReportService.searchSpecialPurchaseDetail(reqVO);
		return restReturnResult;
	}
	
	@PostMapping("/exportSpecialPurchaseDetail")
	@ApiOperation(value = "专项采购详情统计导出", notes = "专项采购详情统计")
	public RestReturnResult exportSpecialPurchaseDetail(
			@RequestBody  SPDetailSearchReqVO reqVO, HttpServletResponse response, HttpServletRequest request){
		RestReturnResult restReturnResult = RestReturnResult.success();
		specialPurchaseReportService.exportSpecialPurchaseDetail(reqVO, response, request);
		return restReturnResult;
	}

	@PostMapping("/groupPurchaseType")
	@ApiOperation(value = "全集团采购方式统计", notes = "全集团采购方式统计")
	public RestReturnResult groupPurchaseType(@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.groupPurchaseType(purchaseTypeReqVO));
		return restReturnResult;
	}

	@PostMapping("/groupPurchaseAmount")
	@ApiOperation(value = "全集团采购数量及金额统计", notes = "全集团采购数量及金额统计")
	public RestReturnResult groupPurchaseAmount(@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.groupPurchaseAmount(purchaseTypeReqVO));
		return restReturnResult;
	}

	@PostMapping("/groupPurchaseAmountExport")
	@ApiOperation(value = "全集团采购数量及金额统计导出", notes = "全集团采购数量及金额统计导出")
	public void groupPurchaseAmountExport(HttpServletResponse response,
										  HttpServletRequest request, @RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		try {
			List<GroupPurchaseAmountVO> ls=specialPurchaseReportService.groupPurchaseAmount(purchaseTypeReqVO);
			String fileName ="全集团采购数量及金额统计.xlsx";
			new ExportExcel("全集团采购数量及金额统计", GroupPurchaseAmountVO.class)
					.setDataListSum(ls)
					.write(request,response, fileName).dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@PostMapping("/areaPurchaseAmount")
	@ApiOperation(value = "各地区采购数量及金额统计", notes = "各地区采购数量及金额统计")
	public RestReturnResult areaPurchaseAmount(@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.areaPurchaseAmount(purchaseTypeReqVO));
		return restReturnResult;
	}

	@PostMapping("/areaPurchaseAmountExport")
	@ApiOperation(value = "各地区采购数量及金额统计导出", notes = "各地区采购数量及金额统计导出")
	public void areaPurchaseAmountExport(HttpServletResponse response,
										  HttpServletRequest request,
										 @RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		try {
			List<AreaPurchaseAmountVO> ls=specialPurchaseReportService.areaPurchaseAmount(purchaseTypeReqVO);
			String fileName ="各地区采购数量及金额统计.xlsx";
			new ExportExcel("各地区采购数量及金额统计", AreaPurchaseAmountVO.class)
					.setDataList(ls)
					.write(request,response, fileName).dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@PostMapping("/groupPurchaseTypeExport")
	@ApiOperation(value = "全集团采购方式统计导出", notes = "全集团采购方式统计导出")
	public void groupPurchaseTypeExport(@RequestBody PurchaseReportReqVO purchaseTypeReqVO,
													HttpServletResponse response,
													HttpServletRequest request){
		try {
			List<GroupPurchaseTypeVO> ls=specialPurchaseReportService.groupPurchaseType(purchaseTypeReqVO);
			String fileName = "全集团采购方式统计.xlsx";
			new ExportExcel("全集团采购方式统计", GroupPurchaseTypeVO.class)
					.setDataListSum(ls)
					.write(request,response, fileName).dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@PostMapping("/searchSpecialPurchaseAbortive")
	@ApiOperation(value = "专项采购流标统计查询", notes = "专项采购流标统计")
	public RestReturnResult searchSpecialPurchaseAbortive(@RequestBody SPAbortiveSearchReqVO reqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult = specialPurchaseReportService.searchSpecialPurchaseAbortive(reqVO);
		return restReturnResult;
	}
	
	@PostMapping("/exportSpecialPurchaseAbortive")
	@ApiOperation(value = "专项采购流标统计导出", notes = "专项采购流标统计")
	public RestReturnResult exportSpecialPurchaseAbortive(@RequestBody SPAbortiveSearchReqVO reqVO ,
          	HttpServletResponse response, HttpServletRequest request){
		RestReturnResult restReturnResult = RestReturnResult.success();
		specialPurchaseReportService.exportSpecialPurchaseAbortive(reqVO, response, request);
		return restReturnResult;
	}

	@PostMapping("/areaPurchaseTypeExport")
	@ApiOperation(value = "各地区采购方式统计", notes = "各地区采购方式统计")
	public void areaPurchaseTypeExport(@RequestBody PurchaseReportReqVO purchaseTypeReqVO,
										HttpServletResponse response,
										HttpServletRequest request){
		try {
			List<AreaPurchaseTypeVO> ls=specialPurchaseReportService.areaPurchaseType(purchaseTypeReqVO);
			String fileName ="各地区采购方式统计.xlsx";
			new ExportExcel("各地区采购方式统计", AreaPurchaseTypeVO.class)
					.setMergedRegionDataList(ls,new Integer[]{0,1},new Integer[]{0,1},null)
					.write(request,response, fileName).dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@PostMapping("/areaPurchaseType")
	@ApiOperation(value = "各地区采购方式统计", notes = "各地区采购方式统计")
	public RestReturnResult areaPurchaseType(@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.areaPurchaseType(purchaseTypeReqVO));
		return restReturnResult;
	}
	
	@PostMapping("/searchDiscussionHistory")
	@ApiOperation(value = "专项采购一事一议统计查询", notes = "专项采购一事一议统计")
	public RestReturnResult searchDiscussionHistory(@RequestBody DiscussionHistorySearchReqVO reqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult = specialPurchaseReportService.searchDiscussionHistory(reqVO);
		return restReturnResult;
	}

	
	@PostMapping("/exportDiscussionHistory")
	@ApiOperation(value = "专项采购一事一议统计导出", notes = "专项采购一事一议统计")
	public RestReturnResult exportDiscussionHistory(@RequestBody DiscussionHistorySearchReqVO reqVO,
          	HttpServletResponse response, HttpServletRequest request){
		RestReturnResult restReturnResult = RestReturnResult.success();
		specialPurchaseReportService.exportDiscussionHistory(reqVO, response, request);
		return restReturnResult;
	}
	
	@PostMapping("/areaPurchaseVariation")
	@ApiOperation(value = "各地区采购变动统计", notes = "各地区采购变动统计")
	public RestReturnResult areaPurchaseVariation(@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.areaPurchaseVariation(purchaseTypeReqVO));
		return restReturnResult;
	}

	@PostMapping("/areaPurchaseVariationExport")
	@ApiOperation(value = "各地区采购变动统计导出", notes = "各地区采购变动统计导出")
	public void areaPurchaseVariationExport(HttpServletResponse response,
										  HttpServletRequest request,
											@RequestBody PurchaseReportReqVO purchaseTypeReqVO){
		try {
			List<AreaPurchaseVariationVO> ls=specialPurchaseReportService.areaPurchaseVariation(purchaseTypeReqVO);
			String fileName ="各地区采购变动统计.xlsx";
			new ExportExcel("各地区采购变动统计", AreaPurchaseVariationVO.class)
					.setDataList(ls)
					.write(request,response, fileName).dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


//	@GetMapping("/exportStrategicPurchaseDetail")
//	@ApiOperation(value = "专项采购详情统计导出", notes = "专项采购详情统计")
//	public RestReturnResult exportStrategicPurchaseDetail(@RequestParam(value = "supplierName",required = false) String supplierName,
//														  @RequestParam(value = "categoryId",required = false) String categoryId,
//														@RequestParam(required = false) Date purchaseStartTime, @RequestParam(required = false) Date purchaseEndTime,
//														HttpServletResponse response, HttpServletRequest request){
//		RestReturnResult restReturnResult = RestReturnResult.success();
//		STDetailSearchReqVO reqVO = new STDetailSearchReqVO();
//		reqVO.setSupplierName(supplierName);
//		reqVO.setCategoryId(categoryId);
//		reqVO.setPurchaseStartTime(purchaseStartTime);
//		reqVO.setPurchaseEndTime(purchaseEndTime);
//		specialPurchaseReportService.exportStrategicPurchaseDetail(reqVO, response, request);
//		return restReturnResult;
//	}


	//战略
//	@PostMapping("/searchStrategicPurchaseDetail")
//	@ApiOperation(value = "战略采购供应商合作详情", notes = "战略采购供应商合作详情")
//	public RestReturnResult searchStrategicPurchaseDetail(@RequestBody STDetailSearchReqVO reqVO){
//		RestReturnResult restReturnResult = RestReturnResult.success();
//		restReturnResult.setData(specialPurchaseReportService.searchStrategicPurchaseDetail(reqVO));
//		return restReturnResult;
//	}
	@PostMapping("/searchStrategicPurchaseDetail")
	@ApiOperation(value = "战略供应商合作详情统计", notes = "战略供应商合作详情统计")
	public RestReturnResult searchStrategicPurchaseDetail(@RequestBody STDetailSearchReqVO reqVO){
		RestReturnResult restReturnResult = RestReturnResult.success();
		restReturnResult.setData(specialPurchaseReportService.searchStrategicDirectDetail(reqVO));
		return restReturnResult;
	}

	@PostMapping("/exportStrategicPurchaseDetail")
	@ApiOperation(value = "战略供应商合作详情统计导出", notes = "战略供应商合作详情统计导出")
	public void exportStrategicPurchaseDetail(@RequestBody STDetailSearchReqVO reqVO,
														  HttpServletResponse response, HttpServletRequest request) throws IOException {
		String fileName = "战略直委采购详情统计.xlsx";
		new ExportExcel("战略直委采购详情统计", STDetailSearchResVO.class).setDataList(specialPurchaseReportService.searchStrategicDirectDetail(reqVO))
				.write(request,response, fileName).dispose();
	}
}
